package com.xxwu.springblogsystem.service;

import com.xxwu.springblogsystem.mapper.BlogMapper;
import com.xxwu.springblogsystem.mapper.UserMapper;
import com.xxwu.springblogsystem.model.Blog;
import com.xxwu.springblogsystem.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BlogMapper blogMapper;

    public User getUserByName(String username) {
        return userMapper.selectUserByUserName(username);
    }

    public User getUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    public User getUserByBlogId(Integer blogId) {
        Blog blog = blogMapper.selectById(blogId);
        if(blog != null) {
            User user = userMapper.selectUserById(blog.getUserId());
            return user;
        }
        return null;
    }
}
